﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataLib.Accounts.Bus;
using System.Data;

namespace Ewts.Storage
{
    public partial class BillsConfirm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                User curUser = new User();
                curUser = (User)Session["UserInfo"];
                if (curUser != null)
                {
                    if (curUser.UserType != "AD")
                    {
                        string belongarea = curUser.CompanyCity;

                        bindData(belongarea);
                    }
                    else
                    {
                        bindData("");
                    }
                }
                else
                { 
                    Response.Redirect("/Accounts/Login.aspx");
                }
            }
        }

        private void bindData(string city)
        {

            string where = "belongarea like '%" + city + "%' and left(loadnum,2)='86'";

            DataTable dt = new DataLib.BLL.LoadNum().GetList(where).Tables[0];


            DataTable data = new DataTable();
            data.Columns.Add("LoadNumid");
            data.Columns.Add("LoadNumNo");
            data.Columns.Add("cumCode");
            data.Columns.Add("cumName");
            data.Columns.Add("collectdate");
            data.Columns.Add("saleman");
            data.Columns.Add("remark1");
            data.Columns.Add("CEDate");
            data.Columns.Add("CADatePay");
            data.Columns.Add("CADateInvice");
            data.Columns.Add("goodsDescribe");
            data.Columns.Add("goodsWeight");
            data.Columns.Add("WRLDate");
            data.Columns.Add("remark2");
            data.Columns.Add("isCJO");
            data.Columns.Add("isWRL");
            data.Columns.Add("isMSF");
            data.Columns.Add("isTran");


            foreach (DataRow row in dt.Rows)
            {
                DataRow dr = data.NewRow();
                dr["LoadNumNo"] = row["loadnum"];

                DataLib.Model.Cumtomer cum = new DataLib.BLL.Cumtomer().GetModel(Convert.ToInt32(row["customerid"]));

                dr["cumCode"] = cum.customercode;
                dr["cumName"] = cum.companyname;
                dr["collectdate"] = row["collectdate"];
                dr["goodsDescribe"] = row["goodsInfo"];
                dr["goodsWeight"] = row["totalWeight"];

                int id=Convert.ToInt32(row["id"]);
                dr["saleman"] = new DataLib.BLL.LoadNum().SalemanByLoad(id).Replace('@', '-').Replace('/', '-'); ; 

                dr["LoadNumid"] = id.ToString();

                DataTable temptable = new DataLib.BLL.BarCode().GetList("loadnumid =" + id).Tables[0];
                if (temptable.Rows.Count != 0  && temptable != null)
                {
                    dr["WRLDate"] = temptable.Rows[0]["createdate"].ToString();
                }
               
                DataTable temp = new DataLib.BLL.BillsConfirm().GetList(" LoadNumID =" +id ).Tables[0];
                if (temp!=null&&temp.Rows.Count!=0)
                {
                    dr["CEDate"] =temp.Rows[0]["CEDate"];
                    dr["CADatePay"] = temp.Rows[0]["CADatePay"];
                    dr["CADateInvice"] = temp.Rows[0]["CADateInvice"];
                    
                    dr["isCJO"] = temp.Rows[0]["isCJO"];
                    dr["isWRL"] = temp.Rows[0]["isWRL"];
                    dr["isMSF"] = temp.Rows[0]["isMSF"];
                    dr["isTran"] = temp.Rows[0]["isTran"];

                    dr["remark2"] = "";
                    dr["remark1"] = "";
                }
                data.Rows.Add(dr);
            }

            rept.DataSource = data;
            rept.DataBind();

        }

        protected string getResult(string str)
        {
            string result = "";
            if (str == "1")
                result = "√";
            else
                result = "";
            return result;

        }
    }
}